﻿#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    //设置鼠标拖拽图像和鼠标滚轮缩放图像
    ui->widget->setInteractions(QCP::iRangeDrag |QCP::iRangeZoom);

    //先添加一条曲线
    ui->widget->addGraph();
    //设置x轴刻度线的数据的格式,默认会有6位小数
    ui->widget->xAxis->setNumberFormat("f");
    //设置数据
    QVector<double> keyVector;
    QVector<double> valueVector;
    for(int i = 0; i < 5; i++)
    {
        keyVector.append(i);
        valueVector.append(2 * i + 3);
    }
    //将数据添加到曲线上
    ui->widget->graph(0)->setData(keyVector, valueVector);
    ui->widget->graph(0)->rescaleValueAxis();
    ui->widget->xAxis->setRange(0, 5);
    //重新绘制
    ui->widget->replot();
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_pushButton_clicked()
{
    ui->widget->setInitViewRect(ui->widget->rect());
}
